package com.example.rbacmanage.service.system.impl;

import com.example.rbacmanage.entity.system.DictData;
import com.example.rbacmanage.entity.system.DictType;
import com.example.rbacmanage.mapper.system.DictDataMapper;
import com.example.rbacmanage.mapper.system.DictTypeMapper;
import com.example.rbacmanage.service.system.DictTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author xiezh
* @description 针对表【t_dict_type】的数据库操作Service实现
* @createDate 2025-03-26 21:09:51
*/
@Service
public class DictTypeServiceImpl implements DictTypeService{
    @Autowired
    private DictTypeMapper dictTypeMapper;
    @Autowired
    private DictDataMapper dictDataMapper;
    @Override
    public void save(DictType dictType) {
        dictType.setCreateTime(new Date());
        dictType.setDelFlag("0");
        dictTypeMapper.insert(dictType);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id : ids) {
            dictTypeMapper.del(id);
        }
    }

    @Override
    public void update(DictType dictType) {
        dictTypeMapper.update(dictType);
    }

    @Override
    public List<DictType> getAll(DictType dictType) {
        List<DictType> list = dictTypeMapper.list(dictType);
        list.forEach(dict->{
            DictData dictData = new DictData();
            dictData.setDictTypeId(dict.getId());
            dict.setDictDataList(dictDataMapper.list(dictData));
        });
        return list;
    }

    @Override
    public PageInfo<DictType> getPage(DictType dictType) {
        PageHelper.startPage(dictType.getPage(),dictType.getLimit());
        return new PageInfo<>(getAll(dictType));
    }

    @Override
    public DictType getById(Long id) {
        return dictTypeMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(DictType dictType) {
        return dictTypeMapper.count(dictType);
    }
}




